<template>
  <div class="app-container">

    <u-page title="消息管理">
      <div slot="header">
        <el-button type="primary" icon="el-icon-edit" @click="hdlOpen(newForm)">
          批量推送信息
        </el-button>
      </div>
      <u-filtered>
        <el-form :inline="true" :model="listQuery" class="search-form">
          <el-form-item label="商户" prop="merchantName">
            <el-input v-model="listQuery.merchantName" placeholder="关键词" clearable />
          </el-form-item>
          <el-form-item label="工号" prop="jobNo">
            <el-input v-model="listQuery.jobNo" placeholder="关键词搜索" clearable />
          </el-form-item>
          <el-form-item label="姓名" prop="name">
            <el-input v-model="listQuery.name" placeholder="关键词搜索" clearable />
          </el-form-item>
          <el-form-item label="创建时间">
            <u-date-time-picker v-model="searchDate" @change="changeSearchDate" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="hdlFilter">查询</el-button>
            <!--            <el-button type="primary" icon="el-icon-download" @click="handleDownload">导出</el-button>-->
          </el-form-item>
        </el-form>
      </u-filtered>

      <u-table
        :data="list"
        :loading="listLoading"
        :options="listOptions"
        :columns="columns"
        :pagination.sync="listQuery"
        :fetch="hdlList"
        @selection-change="hdlSelectChange"
      />

    </u-page>
    <u-dialog title="新增信息" :show.sync="dialogFormVisible" @confirm="hdlCreateQueue()">
      <el-form ref="dialogForm" :model="dataForm" label-width="120px">

        <el-form-item label="消息内容" prop="content">
          <u-tinymce v-model="dataForm.content" :height="300" />
        </el-form-item>
        <el-form-item label="工号" prop="jobNo">
          <el-input v-model="dataForm.jobNo" type="textarea" placeholder="名单" clearable rows="5" />
          <u-tip-info title="格式: 工号+换行或者英文逗号,自动过滤重复数据" />
        </el-form-item>
      </el-form>
    </u-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      dialogReadVisible: false,
      api: this.$u.api.PluginsGuideQueue,
      // 表格
      columns: [{
        prop: 'merchantName',
        label: '商户'
      },
      {
        prop: 'jobNo',
        label: '工号'
      },
      {
        prop: 'name',
        label: '姓名'
      },
      {
        prop: 'content',
        label: '内容'
      },
      {
        prop: 'hasRead',
        label: '是否已读',
        render: (h, params) => {
          const { hasRead } = params.row // 应该解构 hasRead 而不是 read
          if (hasRead === true) {
            return h('span', '已读')
          } else if (hasRead === false) {
            return h('span', '未读')
          }
          return h('span', '未知状态') // 添加默认情况处理
        }
      },
      {
        prop: 'createdAt',
        label: '创建时间',
        timestamp: true
      }
      ],

      list: [],
      listLoading: true,
      listOptions: {
        mutiSelect: true, // boolean 是否多选
        stripe: true // boolean 斑马纹
      },
      listQuery: {
        pageNumber: 1,
        pageSize: 10,
        totalCount: 1,
        title: '',
        status: ''
      },

      dialogFormVisible: false,
      dialogStatus: '',

      dataForm: {},
      textMap: {
        update: '编辑信息',
        create: '新增信息'
      },
      newForm: {
        status: true
      }
    }
  },
  created() {
    this.hdlList()
  },
  methods: {
    hdlCreateQueue() {
      this.api.bathQueue(this.dataForm).then(res => {
        this.$u.msg(res.data)
        this.dialogFormVisible = false
      })
    }
  }
}
</script>
